using UnityEngine;
using System.Collections;

public class RedFlash : Reaction {
	
	Color workingColor;
	
	void Start()
	{
		workingColor = renderer.material.color;
		workingColor.a = 0;
		renderer.material.SetColor("_Color",workingColor);
	}
	
	override protected void pain(float amount)
	{
		StopCoroutine("flash");
		StartCoroutine("flash", amount);
	}
	
	IEnumerator flash(float modifier)
	{
		float lerpTime = .2f;
		float flashTime = 0;
		while(flashTime < lerpTime)
		{
			workingColor.a = Mathf.Lerp(0, modifier, flashTime / lerpTime);
			renderer.material.SetColor("_Color", workingColor);
			yield return 0;
			flashTime += Time.deltaTime;
		}
		
		lerpTime = .1f;
		float startA = workingColor.a;
		flashTime = 0;
		while(flashTime < lerpTime)
		{
			workingColor.a = Mathf.Lerp(startA, 0, flashTime / lerpTime);
			renderer.material.SetColor("_Color", workingColor);
			yield return 0;
			flashTime += Time.deltaTime;
		}
	}
}
